package com.mcflies.commons;

import java.util.List;

import com.mcflies.activity.welcome.R;
import com.mcflies.bean.GridViewBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * @author:mcfly_jun
 * @create_date:2012-8-31
 * @comment:最简单的GridView适配器
 */
public class GridViewBaseAdapter extends BaseAdapter {
	private Context context;
	private List<GridViewBean> beanList;
	private LayoutInflater inflater;

	public GridViewBaseAdapter(Context context, List<GridViewBean> beanList) {
		this.context = context;
		this.beanList = beanList;
		inflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		return beanList.size();
	}

	@Override
	public Object getItem(int position) {
		return beanList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if (null == view) {
			GridViewBean bean = beanList.get(position);
			view = inflater.inflate(R.layout.gridview_main_item, null);

			ImageView gridViewMainItem_IV = (ImageView) view
					.findViewById(R.id.gridViewMainItem_IV);
			gridViewMainItem_IV.setImageBitmap(bean.getBitmap());

			TextView gridViewMainItem_TV = (TextView) view
					.findViewById(R.id.gridViewMainItem_TV);
			gridViewMainItem_TV.setText(bean.getTitle());
		}
		return view;
	}
}
